﻿using Hinacom.Scheduler.Service;
using System.ServiceModel;
using Topshelf;

namespace Hinacom.Scheduler.Hosts.WinService
{
    /// <summary>
    /// 为SchedulerService提供宿主程序，以允许Topshelf控制并启用WCF接口。
    /// </summary>
    public class SchedulerServiceHost : ServiceControl
    {
        private ServiceHost _host;
        private SchedulerService _service;

        public SchedulerServiceHost()
        {
            _service = new SchedulerService();
            _host = new ServiceHost(_service);
        }

        public bool Start(HostControl hostControl)
        {
            _service.Initialize();
            _service.Start();
            _host.Open();
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            _service.Stop();
            _host.Close();
            return true;
        }
    }
}
